Silverlight/WPF: Retreiving the size of a `UIElement` once it has been rendered on screen

Posted by ondesertverge on Stack Overflow See other posts from Stack Overflow or by ondesertverge
Published on 2010-05-26T21:28:55Z Indexed on 2010/05/26 21:31 UTC
Read the original article Hit count: 215

Filed under:
|
|
|

I have the following simple piece of code:

            var canvas = new Canvas();

            foreach (var ztring in strings)
            {
                var textblock = new TextBlock();
                textblock.Text = ztring;

                panel.Children.Add(textblock);

                textblock.Measure(infiniteSize);
            }

At this point I would expect any of the size properties (Height/Width, ActualHeight/ActualWidth, DesiredSize, RenderSize) to give me the size of the textblock. None of them do.

ActualHeight always gives 16.0 no matter what size font. ActualWidth changes according to the text length but not the font size.

I change the font size on the parent container and not the TextBlock itself.

I feel like I am missing some basic element of understanding the manipulation of silverlight elements from within the codebehind.

The question is: how do I get the real actual pixel size of my TextBlock?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about Silverlight